package com.example.administrator.pomelostreet.fragment;


import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.pomelostreet.HttpUtils.FoodFragmentBeen;
import com.example.administrator.pomelostreet.HttpUtils.FoodFragmentParseJson;
import com.example.administrator.pomelostreet.HttpUtils.HttpUtil;
import com.example.administrator.pomelostreet.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class FoodFragment extends Fragment {
    int indext;
    int page=1;
    String path;
    Myhandler handler;

    class Myhandler extends android.os.Handler{
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:

                    break;
            }
        }
    }


    public FoodFragment() {
        // Required empty public constructor
    }




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
     View view=   inflater.inflate(R.layout.fragment_food, container, false);
       return view;

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
//         handler=new Myhandler();

    }

    @Override
    public void onViewCreated(View view,  Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
//         indext = getArguments().getInt("indext");
//         path="http://api.youzibuy.com/brand_area_catalog/item_list?myuid=131221329&tbuid=&device_id=02:00:00:00:00:00&platform=android&v=1.3.2&imei=861483030821249&bundleid=8&mode=0&app_id=7&v_auth=3.fWJkjCzxIALWJiD2lAHhMaTg3eE%252BIe9NMjEkL%252FM7Tpw%253D&sdkversion=23&catalog_id=8&group_id="+indext+"&page="+page+"&size=0 ";
//
//        getFragemtn(indext);

    }

    private void getFragemtn(int indext) {
        switch (indext){
            case 1:
                mRefreshing(path);

                break;
            case 2:

                break;
            case 3:

                break;
            case 4:

                break;
            case 5:

                break;


        }


    }

    private void mRefreshing(final String path) {
        new Thread(){
            @Override
            public void run() {
                super.run();
                byte[] dataUseOkHttp = HttpUtil.getDataUseOkHttp(path);
                String json=new String(dataUseOkHttp);
                if (json!=null&&json.length()>0) {
                    List<FoodFragmentBeen> item_lists =FoodFragmentParseJson.ParseJson(json);
                    Message msg = Message.obtain();
                    msg.obj=item_lists;
                    msg.what=1;
                    handler.sendMessage(msg);
                }
            }
        }.start();

    }


}
